package models;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class Pontuacao {

	private static Connection conexao;
	private static Statement comando;
	
	
	
	/***********************************************************************************/
	
	protected static void conectar() throws SQLException {  
		try {
			Class.forName("org.postgresql.Driver");
		} catch (ClassNotFoundException e) {
		}

			conexao = DriverManager.getConnection(  
			        "jdbc:postgresql://localhost:5432/SGRv2",  
			        "postgres",  
			        "senha");
		
			comando =  conexao.createStatement();
	}

	/***********************************************************************************/
	
	
		  int id;
	      int idregata;
		  int idbarco;
	      String nomebarco;
		  int pontuacao = 0;
	      
	      
	      	public int getid() {
				return id;
			}
	      	public void setid(int id) {
				this.id = id;
			}	      	
	    	
			public int getidregata() {
				return idregata;
			}			
			public void setidregata(int idregata) {
				this.idregata = idregata;
			}
		
			public int getidbarco() {
				return idbarco;
			}
	      	public void setidbarco(int idbarco) {
				this.idbarco = idbarco;
			}
	      	
	      	
	    	public String getnomebarco() {
				return nomebarco;
			}
	      	public void setnomebarco(String nomebarco) {
				this.nomebarco = nomebarco;
			}	

	      	public int getpontuacao() {
				return pontuacao;
			}
	      	public void setpontuacao(int pontuacao) {
				this.pontuacao = pontuacao;
			}	
	      	
	      	/*********************************************************************************/
	      	
	      	public static Pontuacao Pontos(int pontuacaoid) throws SQLException
	      	{
	      		Pontuacao novo = new Pontuacao();
	      		
	      		conectar();
		    	
		    	ResultSet reader = comando.executeQuery("select * from pontuacao where id = " + pontuacaoid);
		    	  
		    	 while (reader.next())
			        {
			            try
			            {
			                novo.setid(((int)reader.getInt("id") ));
			            }
			            catch (Exception e) {
						}
			            try
			            {
			            	   novo.setidbarco(((int)reader.getInt("idbarco") ));
			            }
			            catch (Exception e) {
						}
			            
			            try
			            {
			            	   novo.setidregata(((int)reader.getInt("idregata") ));
			            }
			            catch (Exception e) {
						}
			            
			            try
			            {
			            	   novo.setpontuacao(((int)reader.getInt("pontuacao") ));
			            }
			            catch (Exception e) {
						}			            
			        }
	      		return novo;
	      	}
	      	
	      	/*********************************************************************************/
	      	
	      	public static Pontuacao Pontos(int idbarco, int idregata ) throws SQLException
	      	{
	      		Pontuacao novo = new Pontuacao();
	      		
	      		conectar();
		    	
	      	 	ResultSet reader = comando.executeQuery("select * from pontuacao where idbarco = " + idbarco + " and idregata =" + idregata );
	 		   
		    	 while (reader.next())
			        {  			 
					
			            try
			            {
			                novo.setid(((int)reader.getInt("id") ));
			            }
			            catch (Exception e) {
						}
			            try
			            {
			            	   novo.setidbarco(((int)reader.getInt("idbarco") ));
			            }
			            catch (Exception e) {
						}
			            
			            try
			            {
			            	   novo.setidregata(((int)reader.getInt("idregata") ));
			            }
			            catch (Exception e) {
						}
			            
			            try
			            {
			            	   novo.setpontuacao(((int)reader.getInt("pontuacao") ));
			            }
			            catch (Exception e) {
						}			            
			        }
	      		return novo;
	      	}
	      	
			/*********************************************************************************/
					
			
}
